//
//  LLLabelViewCell.m
//  标签
//
//  Created by admin on 2018/12/10.
//  Copyright © 2018 LG. All rights reserved.
//

#import "LLTagViewCell.h"
#import "LLTagConfig.h"
#import "LLTagModel.h"

@interface LLTagViewCell ()

@property (nonatomic, strong) UIView *normalView;
@property (nonatomic, strong) UIView *selectView;
@property (nonatomic, strong) UILabel *normalLabel;
@property (nonatomic, strong) UILabel *selectLabel;

@end

@implementation LLTagViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.normalView = [[UIView alloc] initWithFrame:self.bounds];
        self.normalView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
        
        self.selectView = [[UIView alloc] initWithFrame:self.bounds];
        self.selectView.backgroundColor = [UIColor grayColor];
        
        self.backgroundView = self.normalView;
        self.selectedBackgroundView = self.selectView;
        
        _normalLabel = [[UILabel alloc] initWithFrame:self.bounds];
        _normalLabel.textColor = UIColorHex(666666);
        _normalLabel.textAlignment = NSTextAlignmentCenter;
        _normalLabel.font = [UIFont systemFontOfSize:13];
        [self.normalView addSubview:_normalLabel];
        
        _selectLabel = [[UILabel alloc] initWithFrame:self.bounds];
        _selectLabel.textColor = [UIColor whiteColor];
        _selectLabel.textAlignment = NSTextAlignmentCenter;
        _selectLabel.font = [UIFont systemFontOfSize:13];
        [self.selectView addSubview:_selectLabel];
        
    }
    return self;
}

- (void)setModel:(LLTagModel *)model
{
    _model = model;
    self.normalLabel.text = model.title;
    self.selectLabel.text = model.title;
    
    self.normalLabel.font = [UIFont systemFontOfSize:model.fontSize];
    self.selectLabel.font = [UIFont systemFontOfSize:model.fontSize];
    
    self.normalLabel.frame = self.bounds;     // 不加上会发生错乱
    self.selectLabel.frame = self.bounds;     // 不加上会发生错乱
    
    
}

- (void)setConfig:(LLTagConfig *)config
{
    _config = config;
    self.normalView.backgroundColor = config.tagNormalbackgroundColor;
    self.selectView.backgroundColor = config.tagSelectbackgroundColor;
    
    if (config.titleNormalbackgroundColor) {
        self.normalLabel.textColor = config.titleNormalbackgroundColor;
    }
    
    if (config.titleSelectbackgroundColor) {
        self.selectLabel.textColor = config.titleSelectbackgroundColor;
    }
    
    // 圆角
    self.normalView.layer.cornerRadius = config.cornerRadius;
    self.selectView.layer.cornerRadius = config.cornerRadius;
    
    if (config.normalBoardColor) {
        self.normalView.layer.borderColor = config.normalBoardColor.CGColor;
        self.normalView.layer.borderWidth = 1;
    }
    
    if (config.selectBoardColor) {
        self.selectView.layer.borderColor = config.selectBoardColor.CGColor;
        self.selectView.layer.borderWidth = 1;
    }
    
}

@end
